package org.handsomezhi.shortlink.admin.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.util.Date;

@Primary
@Component(value = "myMetaObjectHandlerByAdmin")
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
 //       this.strictInsertFill(metaObject, "createTime",LocalDateTime::now, LocalDateTime.class);
//        strictInsertFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
//
        Date date = new Date();
        strictInsertFill(metaObject, "delFlag", () -> 0, Integer.class);
//
       this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        strictInsertFill(metaObject, "updateTime",Date::new, Date.class);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        strictInsertFill(metaObject, "updateTime", Date::new, Date.class);
    }
}
